//
//  UIBarButtonItem+Extension.swift
//  iOSWeibo12
//
//  Created by Admin on 16/9/11.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /*
     快速创建带高亮图片的BarButton
     parameter imageName:            正常时的图片名称
     parameter highlightedImageName: 高亮时的图片名称
     returns: UIBarButtonItem
     */
    convenience init(imageName: String, highlightedImageName: String) {
        let button = UIButton()
        
        button.setBackgroundImage(UIImage(named: imageName), for: UIControlState.normal)
        button.setBackgroundImage(UIImage(named: highlightedImageName), for: UIControlState.highlighted)
        button.sizeToFit()
        
        self.init(customView: button)
    }
    
    /**
     快速创建带高亮图片的BarButton
     parameter imageName:            正常时的图片名称
     parameter highlightedImageName: 高亮时的图片名称
     returns: UIBarButtonItem
     */
    class func createBarButtonItem(imageName: String, highlightedImageName: String) -> UIBarButtonItem {
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: imageName), for: UIControlState.normal)
        button.setBackgroundImage(UIImage(named: highlightedImageName), for: UIControlState.highlighted)
        button.sizeToFit()
        return UIBarButtonItem(customView: button)
    }
}
